// Hps.Tests.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <Hps/Hps.h>

/**
 * Echo client 
 */
class EchoClient
	: public Connection
{
public:
	/**
	 * Constructor
	 **/
	EchoClient (SOCKET socket, Poco::Net::IPAddress& address)
		: Connection(socket, address)
	{
	}

	/**
	 * Destructor
	 **/
	~EchoClient()
	{
	}

	/**
	 * Connection callback
	 **/
	virtual void onConnect()
	{
	}

	/**
	 * Disconnection callback
	 **/
	virtual void onDisconnect()
	{
	}

	/**
	 * Receive callback
	 **/
	virtual int onReceive( BytePtr buffer, Size length )
	{
		this->write (buffer, length);
		return length;
	}
};

/**
 * Main
 **/
int _tmain(int argc, _TCHAR* argv[])
{
	Starter starter;

	SimpleManager<EchoClient>* manager = new SimpleManager<EchoClient>();

	Server server (manager);
	server.start (new SimpleListener(server, 5000));

	while (true)
	{
		std::string bin, bout, rin, rout;

		server.monitor().bandwidth(bin, bout);
		server.monitor().rates(rin, rout);

		system("CLS");

		std::cout << "SERVER STATUS " << std::endl << std::endl

				  << "  Total" << std::endl << std::endl

				  << "    IN:  " << bin << std::endl
				  << "    OUT: " << bout << std::endl << std::endl

				  << "  Rates" << std::endl << std::endl

				  << "    IN:  " << rin << std::endl
				  << "    OUT: " << rout;

		Sleep(1000);
	}

	return 0;
}

